from flask_restful import Resource

from model.crud import QueryMultipleInstances
from model.tables import Follow
from restful.data import DataUid
from restful.response import ResponseSuccess
from restful.session import login_required,data

def _Follow(follows,is_uid=True):
    return [{
        'id':i.id,
        'uid': i.uid if is_uid is not None else i.uid1,
        'time':i.time,
    }for i in follows]

class UserFollow(Resource):
    @data(DataUid())
    def get(self,data):
        #我的关注，uid1
        follows = QueryMultipleInstances(Follow,{'uid':data['uid']})

        #我的粉丝，uid
        fans = QueryMultipleInstances(Follow,{'uid1':data['uid']})
        return ResponseSuccess(data={
            'follows':_Follow(follows,False),
            'fans':_Follow(fans,True)
        })
